//
//  VCBaseViewController.m
//  VCShop
//
//  Created by VoyageCN on 16/8/21.
//  Copyright © 2016年 VoyageCN. All rights reserved.
//

#import "VCBaseViewController.h"
#import "VCHttpTool.h"
#import "UIView+Toast.h"

@interface VCBaseViewController ()

@end

@implementation VCBaseViewController

- (void)POSTRequestWithURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{
    
    [SVProgressHUD show];
    [VCHttpTool POSTRequestWithURL:url
                        params:param
                       success:^(id responseObject) {
                           [SVProgressHUD dismiss];
                            if (returnSuccess) {
                                returnSuccess(responseObject);
                            }
                        } error:^(NSError *error) {
                            [SVProgressHUD dismiss];
                            [self showTostInView:@"请检查网络设置"];
                            if (returnError) {
                                returnError(error);
                            }
                        }];
}

- (void)GETRequestWithURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{
    [SVProgressHUD show];
    [VCHttpTool GETRequestWithURL:url
                           params:param
                          success:^(id responseObject) {
                              [SVProgressHUD dismiss];
                              if (returnSuccess) {
                                  returnSuccess(responseObject);
                              }
                          } error:^(NSError *error) {
                              [SVProgressHUD dismiss];
                              [self showTostInView:@"请检查网络设置"];
                              if (returnError) {
                                  returnError(error);
                              }
                          }];
}

- (void)showTostInView:(NSString *)tost{
    [self.view makeToast:tost duration:1.5 position:@"center"];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
